<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">信息来源</label>
        <el-select v-model="query.sourceType" clearable size="small" placeholder="信息来源" class="filter-item" style="width: 180px" @change="crud.toQuery">
          <el-option v-for="item in sourceTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <label class="el-form-item-label">县/区</label>
        <el-input v-model="query.countyName" clearable placeholder="县/区" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <!--        <label class="el-form-item-label">地址</label>-->
        <!--        <el-input v-model="query.address" clearable placeholder="地址" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <!--       -->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="信息来源">
            <el-radio v-for="item in dict.market_source" :key="item.id" v-model="form.sourceType" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="单位名称">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="省份">
            <el-select v-model="form.provinceName" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.province_info"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="城市">
            <el-input v-model="form.cityName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="县区">
            <el-input v-model="form.countyName" style="width: 370px;" />
          </el-form-item>

          <el-form-item label="电话">
            <el-input v-model="form.phnoe" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="form.address" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="sourceType" label="信息来源">
          <template slot-scope="scope">
            {{ dict.label.market_source[scope.row.sourceType] }}
          </template>
        </el-table-column>
        <el-table-column prop="name" label="单位名称" />
        <el-table-column prop="provinceName" label="省份">
          <template slot-scope="scope">
            {{ dict.label.province_info[scope.row.provinceName] }}
          </template>
        </el-table-column>
        <el-table-column prop="cityName" label="城市" />
        <el-table-column prop="countyName" label="县/区" />
        <el-table-column prop="phnoe" label="电话" />
        <el-table-column prop="address" label="地址" />
        <el-table-column prop="createBy" label="创建者" />
        <el-table-column prop="updateBy" label="更新者" />
        <el-table-column prop="createTime" label="创建日期" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','market:edit','market:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMarket from '@/api/market'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'

const defaultForm = { id: null, sourceType: null, name: null, provinceName: null, cityName: null, countyName: null, phnoe: null, address: null, enabled: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'Market',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['market_source', 'province_info'],
  data() {
    return {
      permission: {
        add: ['admin', 'market:add'],
        edit: ['admin', 'market:edit'],
        download: ['admin', 'market:download'],
        del: ['admin', 'market:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'sourceType', display_name: '信息来源' },
        { key: 'name', display_name: '单位名称' },
        { key: 'provinceName', display_name: '省' },
        { key: 'cityName', display_name: '市' },
        { key: 'countyName', display_name: '县' },
        { key: 'phnoe', display_name: '电话' },
        { key: 'address', display_name: '地址' }
      ],
      sourceTypeOptions: [
        { key: '百度', display_name: '百度' },
        { key: '国家公示系统', display_name: '国家公示系统' },
        { key: '政务网站', display_name: '政务网站' }
      ]
    }
  },
  created() {
    this.crud.optShow = {
      add: true,
      edit: true,
      del: true,
      download: false
    }
  },
  cruds() {
    return CRUD({ title: 'api/market', url: 'api/market', idField: 'id', sort: 'id,desc', crudMethod: { ...crudMarket }})
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
